package com.czk.sort.practice;

import java.util.Arrays;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/11/19 22:28
 */
public class InsertSort {
    public static void main(String[] args) {
        int[] array={2,5,8,4,6,2,1,3,9,10,15,11,7};
        insertSort(array);
    }
    public static void insertSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            int indexValue=i-1;
            int value=array[i];
            while (indexValue>=0&&value<array[indexValue]){
                array[indexValue+1]=array[indexValue];
                indexValue--;
            }
            array[indexValue+1]=value;
        }
        System.out.println(Arrays.toString(array));
    }
}
